﻿/*
* 创建者：LIYINFAI
* 创建时间：2023/10/24 9:35:26
* 描述：
* --------------------------------------
* 修改说明：
* --------------------------------------
*/
using Newtonsoft.Json;
using System;
using System.ComponentModel;
using System.IO;

namespace CommonLibrary
{
    /// <summary>
    /// 氦检仪基础设置
    /// </summary>
    public class HeliumConfig
    {
        /// <summary>
        /// 配置文件路径
        /// </summary>
        private static string CONFIG_FILE_PATH = Path.Combine(CommonHelper.COMMON_CONFIG_DIR, "HeliumSettingConfig.json");
        /// <summary>
        /// 锁
        /// </summary>
        private static object LOCK_OBJ = new object();
        /// <summary>
        /// 实例对象
        /// </summary>
        private static HeliumConfig instance = null;
        /// <summary>
        /// 实例对象
        /// </summary>
        /// <param name="reload"></param>
        /// <returns></returns>
        public static HeliumConfig Instance(bool reload = false)
        {
            if (reload || instance == null)
            {
                try
                {
                    instance = CommonHelper.GetJsonFromFile(CONFIG_FILE_PATH, new HeliumConfig());
                }
                catch (Exception ex)
                {
                    instance = new HeliumConfig();
                    LogHelper.Error(ex);
                }
            }
            return instance;
        }
        /// <summary>
        /// 保存
        /// </summary>
        public void Save()
        {
            lock (LOCK_OBJ)
            {
                CommonHelper.SaveToJsonFile(instance, CONFIG_FILE_PATH);
            }
        }
        /// <summary>
        /// 检漏口压力上限6.00E+002
        /// </summary>
        [Description("检漏口压力上限")]
        [JsonProperty(PropertyName = "LeakPressMax")]
        public float LeakPressMax { get; set; } = 6.00E+02f;
        /// <summary>
        /// 检漏口压力下限=0.00E+00
        /// </summary>
        [Description("检漏口压力下限")]
        [JsonProperty(PropertyName = "LeakPressMin")]
        public float LeakPressMin { get; set; } = 0.00E+00f;
        /// <summary>
        /// 氦检漏率上限(mPa.m3/s)=9.99E-007
        /// </summary>
        [Description("氦检漏率上限")]
        [JsonProperty(PropertyName = "LeakRateMax")]
        public float LeakRateMax { get; set; } = 9.99E-007f;
        /// <summary>
        /// 氦检漏率下限(mPa.m3/s)=1.00E-020
        /// </summary>
        [Description("氦检漏率下限")]
        [JsonProperty(PropertyName = "LeakRateMin")]
        public float LeakRateMin { get; set; } = 1.00E-020f;
        /// <summary>
        /// 背景漏率(mPa.m3/s)=1.00E-005
        /// </summary>
        [Description("背景漏率")]
        [JsonProperty(PropertyName = "BackgroundRate")]
        public float BackgroundRate { get; set; } = 1.00E-005f;
    }
}
